// 函数同样也可以做类型匹配，比如提取参数、返回值的类型。

type GetParameters<Func extends Function> = Func extends (...args: infer Args) => unknown
  ? Args
  : never;

type res = GetParameters<(a: number, b: string) => void>;

// ------------------------------------

// GetReturnType

type GetReturnType<Func extends Function> = Func extends (...args: any[]) => infer ReturnRes
  ? ReturnRes
  : never;

// ------------------------------------

function plus(a: number, b: number): number {
  return a + b;
}

// ReturnType 这个类型 ts中已经内置了
type CopyFnType<T extends Function> = (...args: GetParameters<T>) => GetReturnType<T>;

const plus2: CopyFnType<typeof plus> = (a, b) => {
  return a - b;
};

// ----------- ||| -------------

type CopyFnType2<T extends (...args: any[]) => any> = (...args: GetParameters<T>) => ReturnType<T>;

const plus3: CopyFnType2<typeof plus> = (a, b) => {
  return a - b;
};

export {};
